package com.norteksoft.erm.model;

import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * @hibernate.class table="ERM_USER_TOKEN"
 */

public class UserToken {
	
	public static final String EXTAG="exTag";

	// 令牌OID
	private Long logID = new Long(-1);

	// 令牌
	private String token;

	// 登录成功时间
	private Timestamp loginSucceedTime;

	// 最后访问时间
	private Timestamp lastAccessedTime;

	// 最后一次收到存活信号的时间
	private Timestamp lastAliveTime;

	// 用户名
	private String userName;

	// 用户真实姓名
	private String userRealName;

	// 登录IP
	private String remoteAddr;

	// 当前位置（子系统编号）
	private String location;

	// 用户被授予身份集合（部门、角色、用户自身，String型Set）
	private Set authorities=new HashSet();
	
	//额外的属性，比如说proi/cas的令牌环
	private String exTag;

	public int hashCode() {
		return new HashCodeBuilder().append(logID).append(token).append(
				loginSucceedTime).append(lastAccessedTime)
				.append(lastAliveTime).append(userName).append(userRealName)
				.append(remoteAddr).append(location).toHashCode();
	}

	public UserToken() {
	}

	/**
	 * @hibernate.id generator-class="sequence" column="LOGID"
	 *               unsaved-value="-1" type="long"
	 * @hibernate.generator-param name="sequence" value="ERM_SEQUENCE"
	 */

	public Long getLogID() {
		return logID;
	}

	public void setLogID(Long logID) {
		this.logID = logID;
	}

	/**
	 * @hibernate.property column="TOKEN" length="60" type="string"
	 * @return String
	 */
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	/**
	 * @hibernate.property column="USERNAME" length="30" type="string"
	 * @return String
	 */
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @hibernate.property column="LASTACCESSEDTIME" type="timestamp"
	 * @return Timestamp
	 */
	public Timestamp getLastAccessedTime() {
		return lastAccessedTime;
	}

	public void setLastAccessedTime(Timestamp lastAccessedTime) {
		this.lastAccessedTime = lastAccessedTime;
	}

	/**
	 * @hibernate.property column="LOGINSUCCEEDTIME" type="timestamp"
	 * @return Timestamp
	 */

	public Timestamp getLoginSucceedTime() {
		return loginSucceedTime;
	}

	public void setLoginSucceedTime(Timestamp loginSucceedTime) {
		this.loginSucceedTime = loginSucceedTime;
	}

	/**
	 * @hibernate.property column="REMOTEADDR" length="40" type="string"
	 * @return String
	 */
	public String getRemoteAddr() {
		return remoteAddr;
	}

	public void setRemoteAddr(String remoteAddr) {
		this.remoteAddr = remoteAddr;
	}

	/**
	 * @hibernate.property column="LASTALIVETIME" type="timestamp"
	 * @return Timestamp
	 */
	public Timestamp getLastAliveTime() {
		return lastAliveTime;
	}

	public void setLastAliveTime(Timestamp lastAliveTime) {
		this.lastAliveTime = lastAliveTime;
	}

	/**
	 * @hibernate.property column="USERREALNAME" length="60" type="string"
	 * @return String
	 */
	public String getUserRealName() {
		return userRealName;
	}

	public void setUserRealName(String userRealName) {
		this.userRealName = userRealName;
	}

	/**
	 * @hibernate.property column="LOCATION" length="20" type="string"
	 * @return String
	 */
	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 * @hibernate.property column="AUTHORITIES" length="500"
	 *                     type="com.norteksoft.erm.support.hibernate.usertype.SetAsJSON"
	 * @return String
	 */

	public Set getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set authorities) {
		this.authorities = authorities;
	}
	
	public void addAuthority(String authority){
		this.authorities.add(authority);
	}
	
	/**
	 * @hibernate.property column="EXTAG" length="60" type="string"
	 * @return String
	 */
	public String getExTag() {
		return exTag;
	}

	public void setExTag(String exTag) {
		this.exTag = exTag;
	}

	
	
	
}
